package com.ruoyi.kong.entity;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class KongRoute implements Comparable {
    private String id;
    private List<String> tags = new ArrayList<>();
    private List<String> paths = new ArrayList<>();
    private String destinations;
    private List<String> protocols;
    private Long created_at;
    private String snis;
    private List<String> hosts = new ArrayList<>();
    private String name;
    private boolean preserve_host;
    private int regex_priority;
    private boolean strip_path;
    private String sources;
    private String path_handling;
    private Long updated_at;
    private int https_redirect_status_code = 426;
    private EntityId service;
    private List<String> methods = new ArrayList<>();

    private KongService kongService;
    // 插件信息
    private KongEntity<KongPlugin> kongPlugins;

    @Override
    public int compareTo(Object o) {
        if (o == null) {
            return 1;
        }
        KongRoute upstream = null;
        if (o instanceof KongRoute) {
            upstream = (KongRoute) o;
        }
        return upstream.created_at.compareTo(this.created_at);
    }

    public KongRoute clear() {
        this.snis = set(this.snis);
        this.protocols = set(this.protocols);
        this.paths = set(this.paths);
        this.hosts = set(this.hosts);
        this.methods = set(this.methods);
        return this;
    }

    private String set(String value) {
        if ("".equals(value)) {
            return null;
        }
        return value;
    }

    private List<String> set(List<String> value) {
        if (value == null || value.isEmpty()) {
            return null;
        }
        return value;
    }
}
